home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2002 #11 / Amiga Plus CD - 2002 - No. 11.iso / amigaoscd / amigapluscd / AP-Website / forum / wbboard / search.php < prev    next >
PHP Script  |  2002-03-15  |  15KB  |  349 lines

  1. <?
  2. require("_functions.php");
  3. require("_header.php");
  4. if(!$userdata[canusesearch ]) {
  5.     header("LOCATION: misc.php?action=access_error$session");
  6.     exit;
  7. }
  8. if(!$send && $mode!="daily" && $mode!="user" && !$searchid) {
  9.  
  10.         function makeboardsearchbit($bid,$depth=1) {
  11.           global $boardcache, $permissioncache;
  12.  
  13.           if ( !isset($boardcache[$bid]) ) {
  14.                 return;
  15.           }
  16.  
  17.           while ( list($key1,$val1)=each($boardcache[$bid]) ) {
  18.                 while ( list($key2,$boards)=each($val1) ) {
  19.                 if($boards[invisible] && !$permissioncache[$boards[boardid]]) continue;
  20.                 $out .= "<OPTION value=\"+".$boards[boardid]."\"";
  21.                 if($depth>1) $out .= ">".str_repeat("--",$depth-1)." ".editDBdata($boards[boardname])."</option>";
  22.                 else $out .= ">".editDBdata($boards[boardname])."</option>";
  23.                 $out.=makeboardsearchbit($boards[boardid],$depth+1);
  24.                 } 
  25.           } 
  26.           unset($boardcache[$bid]);
  27.           return $out;
  28.     }
  29.  
  30.     $result = $db_zugriff->query("SELECT * FROM bb".$n."_boards ORDER by boardparentid ASC, sort ASC");
  31.     while ($row = $db_zugriff->fetch_array($result)) $boardcache[$row[boardparentid]][$row[sort]][$row[boardid]] = $row;
  32.     $result = $db_zugriff->query("SELECT boardid FROM bb".$n."_object2board WHERE objectid = '$user_group' AND boardpermission = 1");
  33.     while ($row = $db_zugriff->fetch_array($result)) $permissioncache[$row[boardid]] = 1;
  34.     $board_links = makeboardsearchbit(0);
  35.     $db_zugriff->free_result($result);
  36.         eval("dooutput(\"".gettemplate("search_new")."\");");
  37. }
  38. elseif(!$searchid) {
  39.     if($mode=="daily") {
  40.         $before = 1;
  41.         $searchdate = 1;
  42.         $sortby = "posttime"; 
  43.         $sortorder = "DESC";
  44.     } 
  45.     if($mode=="user") {
  46.         $searchuser = getUsername($userid);
  47.         $exactname = 1;
  48.         $showposts = 1;
  49.         $searchdate = -1;
  50.         $sortby = "posttime"; 
  51.         $sortorder = "DESC";
  52.     }
  53.         if($searchdate!=-1) {
  54.             if($before) $before = ">";
  55.             else $before = "<";
  56.             $posttime = "posttime".$before."'".(time()-($searchdate*86400))."'";
  57.         }
  58.         $forum = $forumchoice;
  59.         if($forumchoice) {
  60.          $tempforumchoice = substr($forumchoice,1);
  61.          $forumchoice="";
  62.         }
  63.             $result = $db_zugriff->query("SELECT boardid FROM bb".$n."_object2board WHERE objectid = '$user_group' AND boardpermission = 1".ifelse($tempforumchoice," AND boardid='$tempforumchoice'",""));
  64.             while ($row = $db_zugriff->fetch_array($result)) $permissioncache[$row[boardid]] = 1;
  65.             $board_result = $db_zugriff->query("SELECT boardid FROM bb".$n."_boards WHERE boardpassword = ''");
  66.                         unset($forumchoice);
  67.                         while($boards = $db_zugriff->fetch_array($board_result)) {
  68.                             if(!$permissioncache[$boards[boardid]]) continue;
  69.                     if($forumchoice) $forumchoice .= " OR "; 
  70.                 $forumchoice .= "boardparentid='$boards[boardid]'";
  71.             }
  72.     if($query) {    
  73.         if($hack_query) {
  74.             $query_array = explode(" ",$query); 
  75.             if($hack_query==1) {
  76.                             
  77.                 for($i = 0; $i < count($query_array); $i++) {
  78.                     if($i) $searchwords .= "AND";
  79.                     $searchwords .= " (";
  80.                     if($posts) $searchwords .= "message like '%".$query_array[$i]."%'";
  81.                     if($posts && $title) $searchwords .= " OR ";
  82.                     if($title) $searchwords .= "posttopic like '%".$query_array[$i]."%'";
  83.                     $searchwords .= " )";                
  84.                 }
  85.             }
  86.             else {
  87.                 $searchwords .= "(";
  88.                 for($i = 0; $i < count($query_array); $i++) {
  89.                     
  90.                     if($i) $searchwords .= " OR ";
  91.                     if($posts) $searchwords .= "message like '%".$query_array[$i]."%'";
  92.                     if($posts && $title) $searchwords .= " OR ";
  93.                     if($title) $searchwords .= "posttopic like '%".$query_array[$i]."%'";
  94.                                 
  95.                 }
  96.                 $searchwords .= " )";    
  97.             }
  98.         } 
  99.         else {
  100.             $searchwords .= "(";
  101.             if($posts) $searchwords .= "message like '%".$query."%'";
  102.             if($posts && $title) $searchwords .= " OR ";
  103.             if($title) $searchwords .= "posttopic like '%".$query."%'";
  104.             $searchwords .= " )";    
  105.         }
  106.     }
  107.     elseif($searchuser) {
  108.         if($exactname) {
  109.             $user = $db_zugriff->query_first("SELECT userid FROM bb".$n."_user_table WHERE username='$searchuser'");
  110.             $searchwords = "bb".$n."_posts.userid='$user[userid]'";
  111.         }
  112.         else {
  113.             $user = $db_zugriff->query("SELECT userid FROM bb".$n."_user_table WHERE username like '%".$searchuser."%'");
  114.             while($row = $db_zugriff->fetch_array($user)) {
  115.                 if(!$m) $searchwords = "(";
  116.                 if($m)     $searchwords .= " OR ";
  117.                 $searchwords .= "bb".$n."_posts.userid='$row[userid]'";
  118.                 $m = 1;    
  119.             }
  120.             if(!$searchwords) $searchwords = "bb".$n."_posts.userid='0'";
  121.             else $searchwords .= ")";
  122.         }
  123.     }
  124.     if(!$forumchoice) {
  125.         eval("dooutput(\"".gettemplate("search_no_result")."\");");
  126.         exit;    
  127.     }
  128.     if($posttime && ($forumchoice || $searchwords)) $posttime .= " AND";
  129.     if($searchwords) $searchwords = "AND ".$searchwords;
  130.     $ssquery = "$posttime ($forumchoice) $searchwords ORDER by $sortby $sortorder";
  131.     
  132.     do {
  133.         $countx++;
  134.         $name = "ssquery".$countx;
  135.     }
  136.     while($$name); 
  137.     $$name = $ssquery;
  138.     session_register("$name");
  139.     eval ("\$output = \"".gettemplate("note27")."\";");
  140.     $ride = "search.php?boardid=$boardid&searchid=$countx&showposts=$showposts$session";
  141.     eval("dooutput(\"".gettemplate("action_ride")."\");");
  142. }
  143. else {        
  144.     $name = "ssquery".$searchid;
  145.     if(!trim($$name)) {
  146.      eval("dooutput(\"".gettemplate("search_no_result")."\");");
  147.      exit();
  148.     }
  149.     $order=substr($$name, strpos($$name, "ORDER"));
  150.     if($showposts) {
  151.         $anzahl = $db_zugriff->query_first("SELECT COUNT(postid)as anzahl FROM bb".$n."_posts WHERE ".$$name);
  152.         $anzahl = $anzahl[anzahl];
  153.         if(!$page) $page=1;
  154.  
  155.         $getpostids=$db_zugriff->query("SELECT postid FROM bb".$n."_posts WHERE ".$$name." LIMIT ".($eproseite*($page-1)).",".$eproseite);
  156.         while($row=$db_zugriff->fetch_array($getpostids)) $postids.=",".$row[postid];
  157.  
  158.         $post_result = $db_zugriff->query("
  159.         SELECT bb".$n."_posts.*,
  160.         bb".$n."_avatars.extension as avatarextension,
  161.         bb".$n."_user_table.*,
  162.         bb".$n."_useronline.zeit,
  163.         bb".$n."_threads.flags
  164.         FROM bb".$n."_posts
  165.         LEFT JOIN bb".$n."_user_table ON (bb".$n."_user_table.userid = bb".$n."_posts.userid)
  166.         LEFT JOIN bb".$n."_avatars ON (bb".$n."_avatars.id = bb".$n."_user_table.avatarid)
  167.         LEFT JOIN bb".$n."_useronline ON (bb".$n."_useronline.userid = bb".$n."_posts.userid)
  168.         LEFT JOIN bb".$n."_threads ON (bb".$n."_threads.threadid = bb".$n."_posts.threadparentid)
  169.         WHERE postid IN (0$postids) ".$order);
  170.  
  171.         $pages=ceil($anzahl/$eproseite);
  172.         $l_hits = 1+($page-1)*$eproseite;
  173.         $h_hits = $page*$eproseite;
  174.         if($h_hits > $anzahl) $h_hits = $anzahl;
  175.         $all_hits = $anzahl;
  176.         
  177.         if($pages>1) $page_link = makepagelink("search.php?boardid=$boardid&searchid=$searchid&showposts=$showposts$session", $page, $pages);
  178.         while($posts = $db_zugriff->fetch_array($post_result)){
  179.         
  180.             unset($posttopic);
  181.             unset($lastedit);
  182.             unset($user_pic);
  183.             unset($signature);
  184.             unset($email);
  185.             unset($userhp);
  186.             unset($quote_and_edit);
  187.             unset($location);
  188.             unset($usericq);
  189.             unset($useraim);
  190.             unset($useryim);
  191.             unset($status);
  192.             unset($stars);
  193.             unset($user_on_off);
  194.             unset($search);
  195.             unset($profile);
  196.             unset($homie);
  197.             unset($pn);
  198.             unset($regdate);
  199.             unset($out);
  200.             
  201.             if($posts[userid]) {
  202.                 if($pms && $userdata[canusepms]) eval ("\$pn = \"".gettemplate("thread_pm")."\";");     
  203.                 $regdate = formatdate($posts[regdate],$regdateformat);
  204.                 $location = htmlspecialchars(editDBdata($posts[location]));
  205.                 $rank = $db_zugriff->query_first("SELECT * FROM bb".$n."_ranks WHERE groupid = $posts[groupid] AND posts<='$posts[userposts]' ORDER by posts DESC LIMIT 1");
  206.                     if($posts[statusextra]) $status = editDBdata($posts[statusextra]);
  207.                 else $status = $rank[rank]; 
  208.         
  209.                         for($i = 0; $i<$rank[mal]; $i++) {
  210.                             $out .= "<img src=\"$rank[grafik]\" border=\"0\">";
  211.                     }
  212.                     $stars = "<a href=\"javascript:rank($rank[id])\" title=\"Informationen zum Rang $rank[rank]\">".$out."</a>";
  213.                     if($posts[avatarid] && !$hide_userpic && $avatars) $user_pic = "<br><img src=\"images/avatars/avatar-".$posts[avatarid].".".$posts[avatarextension]."\" border=0>";
  214.                 if($posts[signatur] && $posts[signature] && !$hide_signature) {
  215.                     $signatur = editSignatur($posts[signatur],$posts[disable_smilies]);
  216.                     eval ("\$signature = \"".gettemplate("thread_signature")."\";");
  217.                 }
  218.                 if($posts[zeit]) eval ("\$user_on_off = \"".gettemplate("thread_useron")."\";");
  219.                 else eval ("\$user_on_off = \"".gettemplate("thread_useroff")."\";");
  220.                 if($posts[users_may_email]==1) eval ("\$email = \"".gettemplate("thread_email")."\";");
  221.                 if($posts[userhp]) eval ("\$userhp = \"".gettemplate("thread_userhp")."\";");
  222.                 if($posts[usericq]) {
  223.                     $usericq = editDBdata($posts[usericq]);
  224.                     eval ("\$usericq = \"".gettemplate("thread_usericq")."\";");
  225.                 }
  226.                 if($posts[aim]) {
  227.                     $aim = editDBdata($posts[aim]);
  228.                     eval ("\$useraim = \"".gettemplate("thread_useraim")."\";");
  229.                 }
  230.                 if($posts[yim]) {
  231.                     $yim = editDBdata($posts[yim]);
  232.                     eval ("\$useryim = \"".gettemplate("thread_useryim")."\";");
  233.                 }
  234.                 eval ("\$search = \"".gettemplate("thread_search")."\";");
  235.                 eval ("\$profile = \"".gettemplate("thread_profile")."\";");
  236.                 eval ("\$homie = \"".gettemplate("thread_homie")."\";");
  237.                 $authorname = $posts[username];
  238.             }
  239.             else eval ("\$authorname = \"".gettemplate("lg_anonymous")."\";");
  240.                         
  241.             $a_name = (($page-1)*$eproseite)+$j+1;
  242.             $backcolor = rowcolor($j++);
  243.         
  244.             if($posts[posticon]) $posticon = "<img src=\"".$posts[posticon]."\">";
  245.             else $posticon = " ";
  246.     
  247.             $posttopic = prepare_topic($posts[posttopic]);
  248.             $post = editPost($posts[message],$posts[disable_smilies]);
  249.     
  250.             if($old_time <= $posts[posttime]) $postsign = "<IMG SRC=\"images/posticonnew.gif\">";
  251.             else $postsign = "<IMG SRC=\"images/posticon.gif\">";
  252.             $posttime = formatdate($posts[posttime],$longdateformat,1);
  253.         
  254.             if($posts[edittime]) {
  255.                 if($posts[editorid]) $editorname = getUsername($posts[editorid]);
  256.                 else eval ("\$editorname = \"".gettemplate("lg_anonymous")."\";");
  257.                 $edittime = formatdate($posts[edittime],$longdateformat);
  258.                 eval ("\$lastedit = \"".gettemplate("thread_lastedit")."\";");
  259.             }
  260.             if($posts[flags]!=1) eval ("\$quote_and_edit = \"".gettemplate("thread_quote_edit")."\";");
  261.             $boardparentid = $posts[boardparentid];
  262.             eval ("\$quote_and_edit = \"".gettemplate("search_showthread")."\";");
  263.             eval ("\$thread_postbit .= \"".gettemplate("thread_postbit")."\";");
  264.         }
  265.         $db_zugriff->free_result($post_result);
  266.         require("_board_jump.php");
  267.         if($thread_postbit) eval("dooutput(\"".gettemplate("search_posts")."\");");
  268.         else eval("dooutput(\"".gettemplate("search_no_result")."\");");
  269.     
  270.     }
  271.     else {
  272.         $result = $db_zugriff->query("SELECT DISTINCT threadparentid FROM bb".$n."_posts WHERE ".$$name);
  273.         $anzahl = $db_zugriff->num_rows($result);
  274.         while($row=$db_zugriff->fetch_array($result)) $allthreadids.=",".$row[threadparentid];
  275.         if(!$page) $page=1;
  276.         
  277.         $getthreadids=$db_zugriff->query("SELECT threadid FROM bb".$n."_threads WHERE threadid IN (0$allthreadids) ORDER BY timelastreply DESC LIMIT ".($tproseite*($page-1)).",".$tproseite);
  278.         while($row=$db_zugriff->fetch_array($getthreadids)) $threadids.=",".$row[threadid];
  279.         
  280.  
  281.         $result = $db_zugriff->query("
  282.         SELECT bb".$n."_threads.*,
  283.         bb".$n."_boards.boardname,
  284.         bb".$n."_user_table.username
  285.         FROM bb".$n."_threads
  286.         LEFT JOIN bb".$n."_boards ON (bb".$n."_boards.boardid=bb".$n."_threads.boardparentid)
  287.         LEFT JOIN bb".$n."_user_table ON (bb".$n."_user_table.userid=bb".$n."_threads.lastposterid)
  288.         WHERE threadid IN (0$threadids) ORDER BY timelastreply DESC");
  289.         
  290.         $pages=ceil($anzahl/$tproseite);
  291.         
  292.         $l_hits = 1+($page-1)*$tproseite;
  293.         $h_hits = $page*$tproseite;
  294.         if($h_hits > $anzahl) $h_hits = $anzahl;
  295.         $all_hits = $anzahl;
  296.         
  297.         if($pages>1) $page_link = makepagelink("search.php?boardid=$boardid&searchid=$searchid&showposts=$showposts$session", $page, $pages);
  298.         while ($threads = $db_zugriff->fetch_array($result)) {
  299.             
  300.             unset($folder_image);
  301.             unset($thread_link);
  302.             unset($anonymous_lp);
  303.             unset($anonymous);
  304.             unset($thread_starter);
  305.             unset($lastauthor);
  306.             
  307.             $sthreadname = "sthread_".$threads[threadid];    
  308.             $boardname = $threads[boardname];        
  309.             if($old_time <= $threads[timelastreply] && $$sthreadname < $threads[timelastreply]) $folder_image .= "new";        
  310.             if($threads[replies] > "15" || $threads[views] > "150") $folder_image .= "hot";
  311.             if($threads[flags]==1) $folder_image .= "lock";
  312.             $folder_image = "<img src=\"images/".$folder_image."folder.gif\">";
  313.             
  314.             if($threads[topicicon]) $posticon = "<img src=\"$threads[topicicon]\">";
  315.             else $posticon = " ";
  316.         
  317.             if($old_time <= $threads[timelastreply] && $$sthreadname < $threads[timelastreply]) eval ("\$thread_link .= \"".gettemplate("board_gofirstnew")."\";");
  318.             $thread_link .= "<font size=2 face=\"$font\"><b>";
  319.             if($threads[important]) eval ("\$thread_link .= \"".gettemplate("board_important")."\";");
  320.             if($threads[pollid]) eval ("\$thread_link .= \"".gettemplate("board_poll")."\";");
  321.             $thread_link .= "<a href=\"thread.php?threadid=$threads[threadid]&boardid=$threads[boardparentid]$session\">".prepare_topic($threads[threadname])."</a></b></font>";
  322.             if(($threads[replies]+1)/$eproseite > 1) $thread_link .= "<font size=1 face=\"$font\"> ( <img src=\"images/multipage.gif\"> <a href=\"thread.php?threadid=$threads[threadid]&boardid=$threads[boardparentid]$session&page=1\">1</a> <a href=\"thread.php?threadid=$threads[threadid]&boardid=$threads[boardparentid]$session&page=2\">2</a> ";
  323.             if(($threads[replies]+1)/$eproseite > 2) $thread_link .= "<a href=\"thread.php?threadid=$threads[threadid]&boardid=$threads[boardparentid]$session&page=3\">3</a> ";
  324.             if(($threads[replies]+1)/$eproseite > 3) $thread_link .= "<a href=\"thread.php?threadid=".$threads[threadid]."&boardid=$threads[boardparentid]$session&page=4\">4</a> ";
  325.             if(($threads[replies]+1)/$eproseite > 4) {
  326.                 $pagesx=ceil(($threads[replies]+1)/$eproseite);
  327.                 eval ("\$thread_link .= \"".gettemplate("board_lastpage")."\";");
  328.             }
  329.             if(($threads[replies]+1)/$eproseite > 1) $thread_link .= ")</font>";
  330.         
  331.             $starttime = formatdate($threads[starttime],$longdateformat,1);
  332.             if($threads[authorid]) $thread_starter = $threads[author];
  333.             else eval ("\$anonymous = \"".gettemplate("lg_anonymous")."\";");
  334.             $lastposttime = formatdate($threads[timelastreply],$longdateformat,1);
  335.             if($threads[lastposterid]) $lastauthor = $threads[username];
  336.             else eval ("\$anonymous_lp = \"".gettemplate("lg_anonymous")."\";");
  337.             eval ("\$last_post = \"".gettemplate("board_lastpost")."\";");
  338.                     
  339.         eval ("\$search_threadbit .= \"".gettemplate("search_threadbit")."\";");
  340.         
  341.         }
  342.         $db_zugriff->free_result($result);
  343.         require("_board_jump.php");
  344.         if($search_threadbit) eval("dooutput(\"".gettemplate("search_threads")."\");");
  345.         else eval("dooutput(\"".gettemplate("search_no_result")."\");");
  346.     }
  347. }
  348. ?>
  349.